package com.yingjia.yingjiauniversity.http.exception;

import com.yingjia.yingjiauniversity.bean.base.SignatureEntity;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;

/**
 * Api请求异常转换.
 *
 * @param <T> the type parameter
 * @author mars.yu
 * @date 2017/11/14
 */
public class ApiServerResultFunction<T> implements Function<SignatureEntity<T>, SignatureEntity<T>> {
    @Override
    public SignatureEntity<T> apply(@NonNull SignatureEntity<T> baseResponse) throws Exception {
        //TODO 异常统一处理 根据服务端返回的错误统一处理
        if (!baseResponse.isSuccess()) {
            throw new ServerException(baseResponse.getCode(), baseResponse.getDesc());
        }
        return baseResponse;
    }
}
